//
//  ZYVisitorTableViewController.swift
//  WeiBo
//
//  Created by zhangyu on 16/9/21.
//  Copyright © 2016年 zhangyu. All rights reserved.
//

import UIKit

class ZYVisitorTableViewController: UITableViewController {
    //  是否登录标示
//    var isLogin = false
    var isLogin: Bool = ZYUserAccountViewModel.sharedUserAccountViewModel.isLogin
    //  访客视图
    var visitorView: ZYVisitorView?
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }
    private func setupVisitorView() {
        visitorView = ZYVisitorView()
        view = visitorView
        //  设置闭包
        visitorView?.loginClosure = { [weak self] in
            
            print("我是访客视图闭包调用过来的")
            self?.requestLoginOperation()
        }
        setupNavUI()
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if !isLogin {
            visitorView?.updateVisitorInfo(message: nil, imageName: nil)
        }
       
    }
    private func setupNavUI() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title:"登录",target:self,action:#selector(loginAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(loginAction))
    }
    @objc private func loginAction(){
        print("login")
        requestLoginOperation()
    }

    //  请求登录的操作
    private func requestLoginOperation() {
        let oAuthVC = ZYOAuthViewController()
        let nav = ZYNavigationViewController(rootViewController: oAuthVC)
        present(nav, animated: true, completion: nil)
        
    }
}
